<?php
/**
 * Created by PhpStorm.
 * User: 游贤川
 * Date: 2021/7/30
 * Time: 22:02
 */

namespace App\Http\Controllers;

use App\Models\LeavingMessage;
use App\Models\Posts;
use App\Models\Prize;
use App\Models\PrizeUser;
use App\Models\RcUser;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;

class RcUserController extends Controller
{


    public function addUser(Request $request)
    {

        //验证
        $verify = [
            'open_id' => 'required',
//            'type' => 'required',
        ];
        $regulation = [
            'open_id.required' => 'open_id必填',
//            'type.required' => 'type必填',
        ];
        $validator = Validator::make($request->all(), $verify, $regulation);
        if ($validator->fails()) {
            return $this->error($validator->errors()->first());
        }
            $data = $request->input();
            $data['type'] = $request->input('type',0);
            $user = RcUser::query()->updateOrCreate(['open_id'=>$data['open_id'],'type'=>$data['type']],$data);
            if ($user){
                return $this->success($user,'成功');
            }
    }

}
